#include "stone.h"

typedef struct{
  int row, col;
  Stone::TYPE type;
}pos_t;

// 棋子在棋盘中的初始行列位置
static pos_t pos[16] = {
    // 初始棋盘第0行
    {0, 0, Stone::CHE},
    {0, 1, Stone::MA},
    {0, 2, Stone::XIANG},
    {0, 3, Stone::SHI},
    {0, 4, Stone::JIANG},
    {0, 5, Stone::SHI},
    {0, 6, Stone::XIANG},
    {0, 7, Stone::MA},
    {0, 8, Stone::CHE},

    // 初始棋盘第2行
    {2, 1, Stone::PAO},
    {2, 7, Stone::PAO},

    // 初始棋盘第3行
    {3, 0, Stone::BING},
    {3, 2, Stone::BING},
    {3, 4, Stone::BING},
    {3, 6, Stone::BING},
    {3, 8, Stone::BING},
};

Stone::Stone()
{

}

/**
 * @brief 初始化棋子位置等
 */
bool Stone::init(int id)
{
    if (id < 0 || id >= STONE_COUNT)
        return false;

    _id = id;
    _dead = false;
    _red = id < 16;

    // 棋盘上半部红棋
    if (id < 16)
    {
        _row = pos[id].row;
        _col = pos[id].col;
        _type = pos[id].type;
    }
    // 棋盘下半部黑棋
    else
    {
        _row = 9 - pos[id - 16].row;
        _col = 8 - pos[id - 16].col;
        _type = pos[id - 16].type;
    }
}

Stone::~Stone()
{

}
